# 此文件主要对数据中的异常点进行排查
import pandas as pd
import numpy as np
from utils.painter import draw_line
import matplotlib.pyplot as plt

if __name__ == "__main__":
    tru = pd.read_csv("data/pre_result/tx/statistical_result/tru.csv")
    # 读取潜空间变量和图片像素
    hidden = pd.read_csv("data/pre_result/tx/statistical_result/hidden.csv")
    image = pd.read_csv("data/pre_result/tx/statistical_result/test_image.csv")/255
    # print(image.loc[29])
    # print(image.loc[30])
    for i in range(-5, 5):
        left = 22
        right = 23
        left += i
        right += i
        print(left)
        print(right)
        a = image.loc[left]
        b = image.loc[right]
        print(np.linalg.norm(a - b))
    image_margin = np.linalg.norm(image - image.shift(1), axis=1)
    hidden_margin = np.linalg.norm(hidden - hidden.shift(1), axis=1).astype(np.float64)
    plt.plot([i for i in range(image_margin.shape[0])], image_margin)
    plt.show()
    print(image_margin.shape)
    print(min(np.round(image_margin, 2)))
    print(hidden_margin.shape)
    print(min(np.round(hidden_margin, 2)))
    draw_line(tru['tru_tx'], [np.round(image_margin, 3), np.round(hidden_margin, 3)],
              ['image_margin', 'hidden_margin'],
              "data/pre_result/tx/statistical_result/img_HD_tx_test.html", 'tx_test',
              mode='one_x_axis', title="tx_test")
